/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    vector<int>res;
    void Travel_In(TreeNode* node,int sum)
    {
        if(node == 0)
            return ;
        
        sum = sum*2 + node->val;
        if(node->left ==0 && node->right == 0)
            res.push_back(sum);

        Travel_In(node->left,sum);
        Travel_In(node->right,sum);
    }

    int sumRootToLeaf(TreeNode* root) 
    {
        Travel_In(root,0);
        int sum = 0 ;
        for(int i=0;i<res.size();i++)
        {
            sum += res[i];
        }
        return sum;

    }
};